<div class="pageBox">
  共&#160;{{ page.paginator.count }}&#160;{{ page.paginator.unit_name }}
{% if page.paginator.num_pages > 1 %}
  {% if page.previous_page_number() %}
  <a href="?{{ s }}page={{ page.previous_page_number() }}">前页</a>
  {% else %}
  前页
  {% endif %}

  {% if page.paginator.num_pages <= 10 %}
        {% for i in page.paginator.page_range %}
          {% if page.number != i %}
          <a href="?{{ s }}page={{ i }}">{{ i }}</a>
          {% else %}
          <span>{{ i }}</span>
          {% endif %}
        {% endfor %}
  {% else %}
        {% if page.number < 5 or page.number > page.paginator.num_pages-4 %}
          {% for i in range(1,6) %}
              {% if page.number != i %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
              {% else %}
              <span>{{ i }}</span>
              {% endif %}
          {% endfor %}
          ...
          {% for i in range(page.paginator.num_pages-4,page.paginator.num_pages+1) %}
              {% if page.number != i %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
              {% else %}
              <span>{{ i }}</span>
              {% endif %}
          {% endfor %}
        {% elif page.number == 5 %}
          {% for i in range(1,7) %}
              {% if page.number != i %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
              {% else %}
              <span>{{ i }}</span>
              {% endif %}
          {% endfor %}
          ...
          {% for i in range(page.paginator.num_pages,page.paginator.num_pages+1) %}
              {% if page.number != i %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
              {% else %}
              <span>{{ i }}</span>
              {% endif %}
          {% endfor %}
        {% elif page.number == page.paginator.num_pages-4 %}
          {% for i in range(1,2) %}
              {% if page.number != i %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
              {% else %}
              <span>{{ i }}</span>
              {% endif %}
          {% endfor %}
          ...
          {% for i in range(page.paginator.num_pages-5,page.paginator.num_pages+1) %}
              {% if page.number != i %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
              {% else %}
              <span>{{ i }}</span>
              {% endif %}
          {% endfor %}
        {% else %}
          {% for i in range(1,2) %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
          {% endfor %}
          ...
          {% for i in range(page.number-4,page.number+5) %}
              {% if page.number != i %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
              {% else %}
              <span>{{ i }}</span>
              {% endif %}
          {% endfor %}
          ...
          {% for i in range(page.paginator.num_pages,page.paginator.num_pages+1) %}
              <a href="?{{ s }}page={{ i }}">{{ i }}</a>
          {% endfor %}
        {% endif %}
  {% endif %}

  {% if page.next_page_number() <= page.paginator.num_pages %}
  <a href="?{{ s }}page={{ page.next_page_number() }}">后页</a>
  {% else %}
  后页
  {% endif %}
{% endif %}
</div>

